//
//  FMViewController.m
//  FMEngineer
//
//  Created by lixl on 17/9/19.
//
//

#import "FMViewController.h"

@interface FMViewController ()

@end

@implementation FMViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.extendedLayoutIncludesOpaqueBars = YES;

}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController  pushViewController:viewController animated:animated];
}
//左右按钮
-(UIButton *)setItemWithTitle:(NSString *)titles isLeft:(BOOL)isLeft {
    UIFont *font=[UIFont systemFontOfSize:14];
    CGSize size = [titles getRectSizeWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) font:font];
    UIButton *titleView=[UIButton buttonWithType:UIButtonTypeCustom];
    [titleView setBackgroundColor:[UIColor clearColor]];
    [titleView setFrame:CGRectMake(0, 0, size.width, 44)];
    [titleView setTitle:titles forState:UIControlStateNormal];
    titleView.titleLabel.font=font;
    [titleView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem =[[UIBarButtonItem alloc] initWithCustomView:titleView];
    if (isLeft) {
        self.navigationItem.leftBarButtonItem=barButtonItem;
    }else{
        self.navigationItem.rightBarButtonItem=barButtonItem;
    }
    return titleView;
}

-(UIButton *)setItemWithImageName:(NSString *)imgName size:(CGSize)btnSize isLeft:(BOOL)isLeft{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, btnSize.width, btnSize.height);
    button.titleLabel.font = [UIFont systemFontOfSize:12];
    [button setBackgroundImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem =[[UIBarButtonItem alloc] initWithCustomView:button];
    if (isLeft) {
        self.navigationItem.leftBarButtonItem=barButtonItem;
    }else{
        self.navigationItem.rightBarButtonItem=barButtonItem;
    }
    return button;
}

-(UIButton *)setLeftBarWithTitle:(NSString *)title{
    self.leftBtn=[self setItemWithTitle:title  isLeft:YES];
    return self.leftBtn;
}

-(UIButton *)setRightBarWithTitle:(NSString *)title{
    self.rightBtn=[self setItemWithTitle:title  isLeft:NO];
    return self.rightBtn;
}
-(UIButton *)setLeftBarWithImageName:(NSString *)imgName size:(CGSize)imgSize{
    self.leftBtn=[self setItemWithImageName:imgName size:imgSize isLeft:YES];
    return self.leftBtn;
}

-(UIButton *)setRightBarWithImageName:(NSString *)imgName size:(CGSize)imgSize{
    self.rightBtn= [self setItemWithImageName:imgName size:imgSize isLeft:NO];
    return self.rightBtn;
}

-(void)setItemwithBack{
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
    [btn setFrame:CGRectMake(0, 0, 20, 20)];
    [btn addTarget:self action:@selector(dismissController) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem=[[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem=leftItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
